package com.hundsun.yr.universal.p2p.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils.NetType;
import com.hundsun.yr.universal.library.utils.RegularUtils;
import com.hundsun.yr.universal.library.widget.HSButton;
import com.hundsun.yr.universal.library.widget.HSEditText;
import com.hundsun.yr.universal.p2p.datahandler.ForgetPasswordResetPwdHandler;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;


/**
 * 忘记密码-输入手机号
 *
 * @author tonglj
 */
public class ForgetPasswordInputPhoneActivity extends BaseActivity implements OnClickListener {

    private HSButton btnGetValidate;
    private HSEditText et_phone;

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return true;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_forgetpass_step1_setphone;
    }

    @Override
    protected void onEveComming(@SuppressWarnings("rawtypes") EventCenter eventCenter) {

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected View getLoadingTargetView() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected void initViewsAndEvents() {
        findView();
        setToolbarTitle(R.string.forgetpassword);
        btnGetValidate.setOnClickListener(this);
        mDataHandler = new ForgetPasswordResetPwdHandler(mContext);
    }

    protected void initImmersionBar() {
        super.initImmersionBar();
        mImmersionBar.titleBar(R.id.common_toolbar).init();
    }

    private void findView() {
        btnGetValidate = findView(R.id.btn_forgetpass_getvalidate);
        et_phone = findView(R.id.forgetpass_et_phone);
    }

    @Override
    protected void onNetworkConnected(NetType type) {
        // TODO Auto-generated method stub

    }

    @Override
    protected void onNetworkDisConnected() {
        // TODO Auto-generated method stub

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onClick(View v) {
        if (isFastDoubleClick()){
            return;
        }

        switch (v.getId()) {
            case R.id.btn_forgetpass_getvalidate:
                String phonetext = et_phone.getPhone();
                if (TextUtils.isEmpty(phonetext)) {
                    showToast(R.string.toast_checkphone_empty);
                    return;
                }
                if (RegularUtils.isPhoneNum(phonetext)) {
                    mDataHandler.interactive(mDataHandler, R.string.method_sendSms,"2", phonetext,"0");
                } else {
                    showToast(R.string.toast_checkphone_err);
                }
                break;

            default:
                break;
        }
    }

    /**
     * 防止按钮连续点击
     */
    private static long lastClickTime;
    public static boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        if ( time - lastClickTime < 500) {
            return true;
        }
        lastClickTime = time;
        return false;
    }
}
